Imports UWPCS3340
Public Class formClass

   Dim cs234 As CS234
   Dim cs334 As CS334

   Private Sub formClass_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

      cs234 = New CS234
      cs334 = New CS334

      AddHandler cs234.PerfectScore, AddressOf HandlesPerfectScore
      AddHandler cs334.PerfectScore, AddressOf HandlesPerfectScore

      rdoCS234.Checked = True

   End Sub

   Private Sub rdoCS234_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
   rdoCS234.CheckedChanged

      updateText(cs234)
      allErrors.Clear()

   End Sub

   Private Sub rdoCS334_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
   rdoCS334.CheckedChanged

      updateText(cs334)
      allErrors.Clear()

   End Sub

   Private Sub updateText(ByVal c As CSSE)
      txtUnit.Text = c.Unit
      txtScore.Text = c.Score
   End Sub

   Private Sub cmdIncrease_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
   cmdIncrease.Click

      allErrors.Clear()
      Try

         If rdoCS234.Checked = True Then

            cs234.Inc()
            updateText(cs234)

         ElseIf rdoCS334.Checked = True Then

            cs334.Inc()
            updateText(cs334)

         End If

      Catch ex As Exception

         allErrors.SetError(txtScore, ex.Message)

         If rdoCS234.Checked = True Then
            updateText(cs234)
         ElseIf rdoCS334.Checked = True Then
            updateText(cs334)
         End If

      End Try

   End Sub

   Private Sub cmdModifyUnit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
   cmdModifyUnit.Click

      allErrors.Clear()

      Try

         If rdoCS234.Checked = True Then

            cs234.Unit = CInt(txtUnit.Text)
            updateText(cs234)

         ElseIf rdoCS334.Checked = True Then

            cs334.Unit = CInt(txtUnit.Text)
            updateText(cs334)

         End If

      Catch ex As Exception

         allErrors.SetError(txtUnit, ex.Message)

         If rdoCS234.Checked = True Then
            updateText(cs234)
         ElseIf rdoCS334.Checked = True Then
            updateText(cs334)
         End If

      End Try

   End Sub

   Private Sub cmdWriteScore_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
   cmdWriteScore.Click

      allErrors.Clear()

      Try

         If rdoCS234.Checked = True Then

            cs234.Score = CInt(txtScore.Text)
            updateText(cs234)

         ElseIf rdoCS334.Checked = True Then

            cs334.Score = CInt(txtScore.Text)
            updateText(cs334)

         End If

      Catch ex As Exception

         allErrors.SetError(txtScore, ex.Message)

         If rdoCS234.Checked = True Then
            updateText(cs234)
         ElseIf rdoCS334.Checked = True Then
            updateText(cs334)
         End If

      End Try

   End Sub

   Public Sub HandlesPerfectScore()

      MsgBox("Perfect Score!", MsgBoxStyle.OkOnly)

   End Sub

   Private Sub cmdClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
   cmdClear.Click

      allErrors.Clear()
      cs234 = New CS234
      cs334 = New CS334

      AddHandler cs234.PerfectScore, AddressOf HandlesPerfectScore
      AddHandler cs334.PerfectScore, AddressOf HandlesPerfectScore

      rdoCS234.Checked = True

      If rdoCS234.Checked = True Then
         updateText(cs234)
      ElseIf rdoCS334.Checked = True Then
         updateText(cs334)
      End If

   End Sub

   Private Sub cmdDone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDone.Click

      Me.Close()

   End Sub

End Class